package com.xdjk.networkdemo.utils;

import android.app.Activity;
import android.content.Intent;

import com.xdjk.networkdemo.R;

/**
 * Created by zhanghs on 2017/8/30.
 */

public class ThemeUtile {

    private static int sTheme;
    public static boolean isNight = false;

    /**
     * Set the theme of the Activity, and restart it by creating a new Activity
     * of the same type.
     */
    public static void changeToTheme(Activity activity, int theme) {
        sTheme = theme;
        activity.finish();
        activity.overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
        activity.startActivity(new Intent(activity, activity.getClass()));
    }

    /**
     * Set the theme of the activity, according to the configuration.
     */
    public static void onActivityCreateSetTheme(Activity activity) {
        switch (sTheme) {
            case ConstantUtils.THEME_LIGHT:
                ThemeUtile.isNight = false;
                activity.setTheme(R.style.CustomThemeLight);
                break;
            case ConstantUtils.THEME_DARK:
                ThemeUtile.isNight = true;
                activity.setTheme(R.style.CustomThemeDark);
                break;
        }
    }
}
